// index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import loginDemo from "@/views/login/loginDemo.vue";
import userDemo from "@/views/user/userDemo.vue";
import coachDemo from '@/views/coach/coachDemo.vue';
import submission_materials from "@/views/user/submission_materials.vue"
import adminDemo from "@/views/admin/adminDemo.vue";
import LearningProgress from '@/views/admin/LearningProgress.vue';
import ExamScores from '@/views/admin/ExamScores.vue';
import student_Instructor from '@/views/user/student_Instructor.vue';
import instructorList from '@/views/admin/instructorList.vue';
import userManage from "@/views/coach/userManage.vue";
import profilePage  from "@/views/coach/profilePage.vue";
import studyPage from "@/views/user/studyPage.vue"
import registrationsPage from "@/views/user/registrationsPage.vue"

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'loginDemo',
    component: loginDemo,
  },
  {
    path: '/userDemo',
    name: 'userDemo',
    component: userDemo,
    redirect: '/userDemo/registrationsPage',
    children: [
      {
        path: 'registrationsPage',
        name: 'registrationsPage',
        component: registrationsPage,
      },
      {
        path: 'submission_materials',
        name: 'submission_materials',
        component: submission_materials
      },
      {
        path: 'student_Instructor',
        name: 'student_Instructor',
        component: student_Instructor,
      },
      {
        path: 'studyPage',
        name: 'studyPage',
        component: studyPage,
      },
    ]
  },
  {
    path: '/coachDemo',
    name: 'coachDemo',
    component: coachDemo,
    redirect: '/coachDemo/userManage',
    children: [
      {
        path: 'userManage',
        name: 'userManage',
        component: userManage,
      },
      {
        path: 'profilePage',
        name: 'profilePage',
        component: profilePage,
      },
    ]
  },
  {
    path: '/adminDemo',
    name: 'adminDemo',
    component: adminDemo,
    redirect: '/adminDemo/LearningProgress',
    children: [
      {
        path: 'LearningProgress',
        name: 'LearningProgress',
        component: LearningProgress,
      },
      {
        path: 'ExamScores',
        name: 'ExamScores',
        component: ExamScores,
      },
      {
        path: 'instructorList',
        name: 'instructorList',
        component: instructorList,
      }
    ]
  },


]

const router = new VueRouter({
  routes
})
// 前置路由守卫
// router.beforeEach((to, from, next) => {
//   const roleId = localStorage.getItem('roleId');

//   // 如果当前路由是登录页面，直接放行
//   if (to.name === 'LoginView') {
//     next();
//     return;
//   }

//   // 根据不同的 roleId 控制访问权限
//   if (roleId === '1') {
//     if (to.path === '/SelectInstitution' || to.path.startsWith('/StudentLayout')) {
//       next();
//     } else {
//       next({ name: 'LoginView' });
//     }
//   } else if (roleId === '2') {
//     if (to.path.startsWith('/InstitutionAdminLayout')) {
//       next();
//     } else {
//       next({ name: 'LoginView' });
//     }
//   } else if (roleId === '3') {
//     if (to.path.startsWith('/SuperAdminLayout')) {
//       next();
//     } else {
//       next({ name: 'LoginView' });
//     }
//   } else {
//     // roleId 不存在时也跳转到登录页面
//     next({ name: 'LoginView' });
//   }
// });
export default router
